<template>
  <div>
    <el-table v-loading="loading" tooltip-effect="darkTable" :data="companyFinanceList" border :height="height" @sort-change="dataSort">
      <el-table-column sortable="custom" :label="$t('融资轮次')" align="center" :prop="type === 'tyc' ? 'rounds' : 'financingRound'" show-overflow-tooltip />
      <el-table-column v-if="type !== 'tyc'" sortable="custom" :label="$t('融资方式')" align="center" prop="financingMode" :formatter="financingModeFormat" show-overflow-tooltip />
      <el-table-column sortable="custom" :label="$t('融资日期')" align="center" :prop="type === 'tyc' ? 'financingTime' : 'financingDate'" show-overflow-tooltip width="110">
        <template slot-scope="scope">
          <span v-if="type === 'tyc'">{{ parseTime(scope.row.financingTime) }}</span>
          <span v-else>{{ parseTime(scope.row.financingDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable="custom" :label="$t('融资总金额') + $t('金额单位')" align="center" :prop="type === 'tyc' ? 'transactionAmount' : 'financingTotalAmount'" show-overflow-tooltip width="150">
        <template slot-scope="scope">
          <span v-if="type === 'tyc'">{{ moneyFormat(isNaN(Number(scope.row.transactionAmount)) ? '' : scope.row.transactionAmount, 'w') }}</span>
          <span v-else>{{ moneyFormat(scope.row.financingTotalAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable="custom" :label="$t(type === 'tyc' ? '估值':'融资前估值') + $t('金额单位')" align="center" :prop="type === 'tyc' ? 'valuation' : 'financingBeforeValuation'" show-overflow-tooltip width="150">
        <template slot-scope="scope">
          <span v-if="type === 'tyc'">{{ moneyFormat(scope.row.valuation, 'w') }}</span>
          <span v-else>{{ moneyFormat(scope.row.financingBeforeValuation, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="type !== 'tyc'" sortable="custom" :label="$t('融资后估值') + $t('金额单位')" align="center" prop="financingAfterValuation" show-overflow-tooltip width="150">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.financingAfterValuation, 'w') }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
  import { listCompanyFinance } from '@/api/company/finance/companyFinance'
  import { listCompanyFinanceTyc } from '@/api/company/finance/companyFinanceTyc'
  export default {
    name: 'CompanyFinanceInfo',
    props: {
      // 公司ID
      bussId: {
        type: String,
        required: true
      },
      height: {
        type: String,
        default: () => ''
      },
      type: {
        type: String,
        default: undefined
      }
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 融资历史表格数据
        companyFinanceList: [],
        // 查询参数
        queryParams: {
          companyId: this.bussId,
          prop: undefined,
          order: undefined
        },
        // 表单参数
        form: {},
        financingModeOptions: []
      }
    },
    created() {
      this.getList()
      this.getDicts('financing_mode').then(response => {
        this.financingModeOptions = response.data
      })
    },
    methods: {
      /** 查询新闻信息列表 */
      getList() {
        this.loading = true
        this.queryParams.companyId = this.bussId
        if (this.type === 'tyc') {
          listCompanyFinanceTyc(this.queryParams).then(response => {
            this.companyFinanceList = response.rows
            this.total = response.total
            this.loading = false
            })
        } else {
          listCompanyFinance(this.queryParams).then(response => {
            this.companyFinanceList = response.rows
            this.total = response.total
            this.loading = false
          })
        }
      },
      openNews(row) {
        if (row.newUrl.indexOf('http://') !== -1) {
          window.open(row.newUrl)
        } else if (row.newUrl.indexOf('https://') !== -1) {
          window.open(row.newUrl)
        } else {
          window.open('http://' + row.newUrl)
        }
      },
      // 融资方式字典翻译
      financingModeFormat(row) {
        return this.selectDictLabel(this.financingModeOptions, row.financingMode)
      },

      // 排序
      dataSort(column) {
        this.loading = true
        if (column.order !== null && column.order !== undefined && column.order !== '') {
          this.queryParams.prop = column.prop
          if (column.order === 'ascending') {
            this.queryParams.order = 'asc'
          } else if (column.order === 'descending') {
            this.queryParams.order = 'desc'
          }
        } else {
          this.queryParams.prop = undefined
          this.queryParams.order = undefined
        }
        this.getList()
      }
    }
  }
</script>
